<template>
  <avue-crud :data="dataSource" :option="crudTaskHistoryOption"></avue-crud>
</template>
<script>
import taskHistoryOption from "./taskHistoryOption";
import {deepClone} from "utils/util";

const taskTemplate = {
  authComment: null,
  authDateTime: null,
  candidateUserConfig: null,
  candidateUsers: null,
  createTime: null,
  durationInMillis: null,
  handlerState: null,
  nodeFormOption: null,
  taskConfig: null,
  taskDefKey: null,
  taskDefName: "开始",
  taskFormConfig: null,

  taskInstFormData: null,
  taskInstId: null,
  taskOwnerUser: null
}
export default {
  computed: {
    crudTaskHistoryOption() {
      return taskHistoryOption
    }
  },
  props: {
    modelValue: Array,
    startUser: Object,
    startTime: {
      type: String,
    },
    endTime: {
      type: String,
    }
  },
  data() {
    return {
      dataSource: []
    }
  },
  created() {
    this.initStartTask()
    this.initEndTask();
  },
  methods: {

    initStartTask() {
      let dataSource = deepClone(this.modelValue || [])
      let startTask = deepClone(taskTemplate);
      startTask.taskHandlerUser = this.startUser;
      startTask.taskDefName = "开始";
      startTask.createTime = this.startTime;
      startTask.authDateTime = this.startTime;
      startTask.durationInMillis =0;
      dataSource.push(startTask)
      this.dataSource = dataSource;
    },
    initEndTask() {
      if (!this.endTime) {
        return
      }
      let endTask = deepClone(taskTemplate);
      endTask.taskHandlerUser = this.startUser;
      endTask.taskDefName = "结束";
      endTask.createTime = this.endTime;
      endTask.authDateTime = this.endTime;
      this.dataSource.unshift(endTask)

    }
  }

}
</script>
<style scoped>

</style>
